<template>
	<view @click="outerFile()">
		<slot></slot>
	</view>
</template>

<script setup>
	// #ifdef APP-PLUS
	import {
		createNewFile
	} from "@/uitls/androidTool.js"
	// #endif
	import {
		dateTypeFormat,myShowToast
	} from "@/uitls/tool.js"
	import {
		ref
	} from "vue"
	import store from "@/store/index.js"
	let now = dateTypeFormat("YYYY-mm-dd", new Date)
	const outerFile = async () => {
		let txtName=`AccountBook_${now}.txt`
		// #ifdef APP-PLUS
		let isCreate = await createNewFile(txtName, store.state.mainData.allData)
		if (isCreate) {
			myShowToast(`成功保存到/Download/${txtName}`)
		} else {
			myShowToast("保存失败")
		}
		// #endif
		// #ifdef H5
		// 将详细信息转换为JSON字符串
		let jsonString = JSON.stringify(store.state.mainData.allData, null, 2);
		// 创建一个Blob对象，包含JSON字符串
		let export_blob = new Blob([jsonString], {type: "application/json"});
		let urlObject = window.URL || window.webkitURL || window;
		let save_link = document.createElementNS("http://www.w3.org/1999/xhtml", "a")
		save_link.href = urlObject.createObjectURL(export_blob);
		save_link.download = txtName;
		save_link.click();
		// #endif
	}
</script>

<style lang="scss">

</style>